package text;

public class Node <T>{
    LNode head = new LNode();
    //头插法
    public void insideAtHead(T date){
        LNode<T> a = new LNode();
        a.date =(T) date;
        a.next=head.next;
        head.next=a;

    }
    //尾插法
    public void insideAtTail(T date){
        LNode b=head;
        LNode tail = new LNode();
        tail.date=(T) date;
       if(head==null){
           tail.next=head.next;
           head=tail;
       }
       else{
          while(b.next!=null){
             b=b.next;
          }
          tail.next=b.next;
          b.next=tail;

       }
    }
    //逆序
    public void reverse(){
        LNode first = head.next;
        for(LNode node = head.next.next; node!=null; node=first.next){
            first.next = node.next;
            node.next = head .next;
            head.next = node;
        }
    }

    //打印
    public void display() {
        if (head.next == null) {
            System.out.print("这是一张空表");
            return;
        } else {
            for (LNode node = head.next; node != null; node = node.next) {
                System.out.print(node.date + " ");
            }
            System.out.println();
        }
    }
}
